package com.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.builder.ExcelWriterBuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Package: com.excel
 * @ClassName: Main
 * @Author: wulongkai
 * @CreateTime: 2024/3/20 17:24
 * @Description:
 */
public class Main {
    public static void main(String[] args) {
        // 文件输出位置
        String fileName = "/Users/a58/Desktop/test.xlsx";
        // 模拟下拉框内容
        Map<Integer, List<String>> selectMap = new HashMap<>();
        List<String> sexList = new ArrayList<>();
        sexList.add("性别");
        sexList.add("男");
        sexList.add("女");
        selectMap.put(1, sexList);
        List<String> typeList = new ArrayList<>();
        typeList.add("类型");
        typeList.add("股票");
        typeList.add("基金");
        typeList.add("债券");
        selectMap.put(2, typeList);
        // 模拟表头
        List<List<String>> headList = new ArrayList<>();
        List<String> field1 = new ArrayList<>();
        List<String> field2 = new ArrayList<>();
        List<String> field3 = new ArrayList<>();
        field1.add("编号");
        field2.add("性别");
        field3.add("类型");
        headList.add(field1);
        headList.add(field2);
        headList.add(field3);
        ExcelWriterBuilder builder = EasyExcel.write(fileName);
        builder.head(headList)
                .registerWriteHandler(new SelectSheetWriteHandler(selectMap))
                .sheet("模板")
                .doWrite(new ArrayList());

    }
}
